const OSS = require('ali-oss');
const accessKeyId = "LTAI5tL9WmHeGCQ7nLHcAF6p"
const accessKeySecret = "IHa6HX3wQbKvtwfCrGgjHg3LoTDuSg"
const bucketName = "huogu"
const fs = require('fs')
const regionName = "oss-cn-hangzhou"
const host = "https://huogu.oss-cn-hangzhou.aliyuncs.com/"

const client = new OSS({
    // 必选参数
    accessKeyId: accessKeyId,
    accessKeySecret: accessKeySecret,
    region: regionName,
    bucket: bucketName
})

async function uploadFile(filepath, filename) {
    try {
        const result = await client.put(filename, filepath)
        return result.url
    } catch (e) {
        console.log(e.message)
        return "上传失败"
    }
}


module.exports = {
    uploadFile,
}